package org.dfzt.modules.online.cgform.converter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.dfzt.common.util.MyClassLoader;
import org.dfzt.common.util.SpringContextUtils;
import org.dfzt.common.util.oConvertUtils;
import org.dfzt.modules.online.cgform.converter.bb.b;
import org.dfzt.modules.online.cgform.converter.bb.c;
import org.dfzt.modules.online.cgform.converter.bb.d;
import org.dfzt.modules.online.cgform.converter.bb.e;
import org.dfzt.modules.online.cgform.converter.bb.f;
import org.dfzt.modules.online.cgform.converter.bb.h;
import org.dfzt.modules.online.cgform.entity.OnlCgformField;

public class a {
    private static final Logger a = LoggerFactory.getLogger(a.class);

    private static final String b = "list";

    private static final String c = "radio";

    private static final String d = "checkbox";

    private static final String e = "list_multi";

    private static final String f = "sel_search";

    private static final String g = "sel_tree";
    private static final String h = "cat_tree";
    private static final String i = "link_down";
    private static final String j = "sel_depart";
    private static final String k = "sel_user";
    private static final String l = "pca";

    public static FieldCommentConverter a(OnlCgformField paramOnlCgformField) {
        h h1;
        f f1;
        e e1;
        b b1;
        d d1;
        a a1;
        String str = paramOnlCgformField.getFieldShowType();
        c c1 = null;
        switch (str) {
            case "list":
            case "radio":
                return new c(paramOnlCgformField);
            case "list_multi":
            case "checkbox":
                return new f(paramOnlCgformField);

            case "sel_search":
                return new d(paramOnlCgformField);

            case "sel_tree":
                return new h(paramOnlCgformField);

            case "cat_tree":
                return new org.dfzt.modules.online.cgform.converter.bb.a(paramOnlCgformField);

            case "link_down":
                return new org.dfzt.modules.online.cgform.converter.bb.e(paramOnlCgformField);

            case "sel_depart":
                return new org.dfzt.modules.online.cgform.converter.bb.b(paramOnlCgformField);

            case "sel_user":
                return new org.dfzt.modules.online.cgform.converter.bb.i(paramOnlCgformField);

            case "pca":
                return new org.dfzt.modules.online.cgform.converter.bb.g(paramOnlCgformField);
        }


        return null;
    }


    public static Map<String, FieldCommentConverter> a(List<OnlCgformField> paramList) {
        HashMap hashMap = new HashMap();
        for (OnlCgformField onlCgformField : paramList) {
            FieldCommentConverter fieldCommentConverter = null;
            if (oConvertUtils.isNotEmpty(onlCgformField.getConverter())) {
                fieldCommentConverter = a(onlCgformField.getConverter().trim());
            } else {
                fieldCommentConverter = a(onlCgformField);
            }
            if (fieldCommentConverter == null) {
                continue;
            }
            hashMap.put(onlCgformField.getDbFieldName(), fieldCommentConverter);
        }
        return hashMap;
    }


    private static FieldCommentConverter a(String paramString) {
        Object object = null;
        if (paramString.indexOf(".") > 0) {
            try {
                object = MyClassLoader.getClassByScn(paramString).newInstance();
            } catch (InstantiationException instantiationException) {
                a.error(instantiationException.getMessage(), instantiationException);
            } catch (IllegalAccessException illegalAccessException) {
                a.error(illegalAccessException.getMessage(), illegalAccessException);
            }
        } else {
            object = SpringContextUtils.getBean(paramString);
        }
        if (object != null && object instanceof FieldCommentConverter) {
            return (FieldCommentConverter) object;
        }

        return null;
    }
}
